home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-04-02 | 16.5 KB | 455 lines | [TEXT/MPS ] |
- {
- COPYRIGHT (C) 1984-1990 Apple Computer,Inc.
- All rights reserved
-
- Resource editor interface unit for instances of editors and pickers. This should be
- USE'd by any pascal implementation of a resource editor or picker. The
- companion file ResDisp.a.o should be linked with the pascal to build
- the file for inclusion in ResEdit.
-
- Pickers are given a resource type and should display all of that type in
- the current resfile in a suitable format. If the picker is given an open call
- AND there's a compatible editor, it should give birth to the Editor. The editor
- is given a handle to the resource object and it should open up an edit
- window for the user.
-
- Note that anybody can open pickers and editors so, for instance, a dialog item list
- editor might open an icon Picker for the user to choose an appropriate icon.
- The user could also, while in the icon picker, open the icon editor to create
- a new icon if desired. }
-
-
- UNIT ResEd;
-
-
- INTERFACE
-
- Uses Memtypes, QuickDraw, OSIntf, ToolIntf, Printing;
-
-
- CONST
-
- { Standard menus exported by ResEdit }
-
- fileMenu = 2;
-
- newFileItem = 1;
- openFileItem = 2;
- openSpecialItem = 3;
- closeItem = 4;
- saveItem = 5;
- revertItem = 6;
- getThisInfoItem = 8;
- getInfoItem = 9;
- verifyItem = 10;
- pageSetupItem = 12;
- printItem = 13;
- preferencesItem = 15;
- quitItem = 17;
-
- { Masks for AbleMenu - normally not used directly. }
- newFileMask = $2;
- openFileMask = $4;
- openSpecialMask = $8;
- closeMask = $10;
- saveMask = $20;
- revertMask = $40;
- getThisInfoMask = $100;
- getInfoMask = $200;
- verifyMask = $400;
- pageSetupMask = $1000;
- printMask = $2000;
- preferencesMask = $08000;
- quitMask = $020000;
- disabledMask = $1;
-
- { Mask combinations to be used in calls to AbleMenu. }
- fileNotOpen = disabledMask + newFileMask + openFileMask + openSpecialMask + getInfoMask +
- verifyMask + pageSetupMask + preferencesMask + quitMask;
- fileNoPrint = fileNotOpen + getThisInfoMask + closeMask + saveMask + revertMask;
- fileAll = fileNoPrint + printMask;
- fileDA = disabledMask + closeMask + quitMask;
-
- rsrcMenu = 128;
-
- rsrcCreateItem = 1;
- rsrcOpenItem = 2;
- rsrcOpenTemplateItem= 3;
- rsrcOpenHexItem = 4;
- rsrcRevertItem = 6;
- rsrcGetInfoItem = 8;
-
- rsrcCreateMask = $2;
- rsrcOpenMask = $4;
- rsrcOpenTemplateMask= $8;
- rsrcOpenHexMask = $10;
- rsrcRevertMask = $40;
- rsrcGetInfoMask = $100;
- rsrcDisabledMask = $FFFFFE01;
-
- rsrcDisabled = $FFFFFE00;
- rsrcRevertOnly = rsrcDisabledMask + rsrcRevertMask;
- rsrcPickerNoSel = rsrcDisabledMask + rsrcCreateMask;
- rsrcFilePicker = rsrcPickerNoSel + rsrcRevertMask + rsrcOpenMask;
- rsrcRsrcPicker = rsrcFilePicker + rsrcOpenHexMask + rsrcOpenTemplateMask + rsrcGetInfoMask;
- rsrcEditor = rsrcDisabledMask + rsrcRevertMask + rsrcGetInfoMask;
- rsrcEditorPicker = rsrcEditor + rsrcOpenMask + rsrcOpenTemplateMask + rsrcOpenHexMask;
- rsrcDITLEd = rsrcEditorPicker - rsrcOpenHexMask + rsrcCreateMask;
- rsrcEditorCreate = rsrcEditor + rsrcCreateMask;
-
- editMenu = 3;
-
- undoItem = 1;
- cutItem = 3;
- copyItem = 4;
- pasteItem = 5;
- clearItem = 6;
- dupItem = 8;
- selectAllItem = 9;
- selectChangedItem =10;
-
- { Masks for AbleMenu - normally not used directly. }
- undoMask = $2;
- cutMask = $8;
- editCopyMask = $10;
- pasteMask = $20;
- clearMask = $40;
- duplicateMask = $100;
- selectAllMask = $200;
- selectChangedMask=$400;
- editDisabledMask= $FFFFF801;
-
- { Mask combinations to be used in calls to AbleMenu. }
- editNone = editDisabledMask - 1;
- editClear = editDisabledMask + clearMask;
- editCopy = editDisabledMask + editCopyMask;
- editPaste = editDisabledMask + pasteMask;
- editUndoPasteOnly = editPaste + undoMask;
- editDup = editClear + duplicateMask;
- editNoDup = editDisabledMask + cutMask + editCopyMask + pasteMask + clearMask; { No dup or undo }
- editNoUndo = editNoDup + duplicateMask;
- editUndNoDup= editNoDup + undoMask;
- editAll = editNoUndo + undoMask;
- editAcc = editUndNoDup; { for DAs }
-
- viewMenu = 130; { Type pickers view menu. }
-
- viewByIDItem = 1;
- viewByNameItem = 2;
- viewBySizeItem = 3;
- viewByOrderItem = 4;
- viewBySpecialItem = 5;
- viewShowAttributesItem = 7;
-
- { Masks for AbleMenu. }
- viewByIDMask = $2;
- viewByNameMask = $4;
- viewBySizeMask = $8;
- viewByOrderMask = $10;
- viewBySpecialMask = $20;
- viewShowAttributesMask = $80;
- viewDisabledMask = $FFFFFF01;
-
- viewNoSpecial = viewDisabledMask + viewByIDMask + viewByNameMask + viewBySizeMask + viewByOrderMask + viewShowAttributesMask;
- viewNoAttributes = viewDisabledMask + viewByIDMask + viewByNameMask + viewBySizeMask + viewByOrderMask + viewBySpecialMask;
- viewAll = viewNoAttributes + viewShowAttributesMask;
-
- editorNameChr = CHR(0); { First char of the name for editors }
-
- { Standard strings available by calling GetStr. }
- editStrings = 130; { Resource ID of STR# resource containing the strings. }
- undoChangeStr = 1;
- redoChangeStr = 2;
- undoCutStr = 3;
- redoCutStr = 4;
- undoCopyStr = 5;
- redoCopyStr = 6;
- undoClearStr = 7;
- redoClearStr = 8;
- undoTypingStr = 9;
- redoTypingStr = 10;
- undoPasteStr = 11;
- redoPasteStr = 12;
- undoStr = 13;
-
- miscStrings = 129; { Resource ID of STR# resource containing the strings. }
- miscStringsName = 'Misc'; { Accessing resources by name is preferred }
- fromStr = 1; { String for window titles. }
- cantLoadSndErrStr = 24; { Snd picker string. }
- fullWindowStr = 38; { String for the resizeWind menu item }
- ownerWindowWindowStr= 39;
- newItemStr = 40; { Enter new item number }
- selectItemStr = 41; { Open which item? }
- clipBoardErrorStr = 42; { Error accessing the Clipboard. }
- sndErrorStr = 43; { Error playing a sound. }
- openUsingStr = 44; { Open using Template… }
- openAsDITMStr = 45; { Open As Dialog Item }
- openDITMStr = 77; { Open Item }
-
- { Text for selected errors }
- errorStrings = 132; { Resource ID of STR# resource containing the error strings }
- errorStringsName = 'Errors'; { Accessing resources by name is preferred }
- genericErrStr = 1; { Returned by GetErrorText when no specific message available }
- ioErrStr = 1;
- writeProtectErrStr = 2;
- diskFullErrStr = 3;
- fileLockedErrStr = 4;
- outOfMemoryErrStr = 5;
- alreadyOpenErrStr = 6;
- tooManyOpenErrStr = 7;
- volNotMountedErrStr = 8;
- resNotFoundErrStr = 9;
- accessErrStr = 10;
- resFileNotFoundErrStr = 11;
- addResFailErrStr = 12;
- removeResFailErrStr = 13;
- resAttributesErrStr = 14;
- resMapErrStr = 15;
- fileNotFoundErrStr = 16;
- eofErrStr = 17;
-
- arrowCursor = -1; { Used in the call to SetTheCursor to set the arrow cursor. }
-
- minPickStdWidth = 150;
- minPickStdHeight = 64;
-
- theScrollBar = 15; { Width of a scroll bar. }
- pickerGaps = 6; { 4 bet graphic & frame, 2 for frame }
-
- okChoice = 1;
-
- noDialog = 0;
-
- alertStringsName = 'Alert strings';
- badCharAlert = 1; { ALRT, DLOG, WIND editors }
- revertResourceAlertStr = 2;
- noTemplateAlert = 6; { GNRL editor }
- cantPlayOnThisMachineAlert = 7; { snd picker }
- cantPlaySndAlert = 8; { snd picker }
-
- { Consts for Resource menu string }
- rsrcStrName = 'Resource menu';
- rsrcCreateStr = 1;
- rsrcOpenStr = 2;
- rsrcListStr = 3;
- rsrcOpenLists = 4;
- rsrcOpenEditor = 5;
- rsrcOpenEditors = 6;
- rsrcOpenHex = 7;
- rsrcRevert = 8;
- rsrcRevertThese = 9;
- rsrcResources = 10;
- rsrcRevertRes = 11;
- rsrcRevertThis = 12;
- rsrcPatCreateStr = 13;
- rsrcSICNCreateStr = 14;
- rsrcDITLCreateStr = 15;
- rsrcRevertItemStr = 16;
- rsrcGNRLCreateStr = 17;
-
- TYPE
- STR64 = STRING[64];
-
- AlertType = (displayTheAlert, displayStopAlert, displayNoteAlert, displayCautionAlert,
- displayYNAlert, displayYNCAlert, displayYNCStopAlert);
-
- { Map entry definition for new resource manager calls. }
- ResMapEntry = RECORD
- RID: INTEGER;
- RNameOff: INTEGER;
- RLocn: LongInt;
- RHndl: Handle;
- END;{ ResMapEntry }
-
- { This structure is used by the GetQuickDrawVars procedure. }
- pQuickDrawVars = ^QuickDrawVars;
- QuickDrawVArs = RECORD
- randSeed: LONGINT;
- screenBits: BitMap;
- arrow: Cursor;
- dkGray: Pattern;
- ltGray: Pattern;
- gray: Pattern;
- black: Pattern;
- white: Pattern;
- thePort: GrafPtr;
- END; { QuickDrawVars }
-
-
- { Each driver has its own object handle. This has to start with a handle
- to its parent's object followed by the name distinguishing the father
- This name will be part of the son's window title. The next field should
- be the window of the obj (may be used by son to get back to the father
- (through the refcon in the windowRec). The next field is the rebuild flag
- used to indicate that a windows data (e.g. a pickers list) needs to be
- recalculated at the next opportunity. The rest of the handle can be of
- any format. The name for pickers should be the name of the file or disk.
- For editors, the name should be the complete name (not the windows title)
- preceded by an editorNameChr character (see const above). An example of a
- complete name would be "ALRT ID = -1234 from AFile". This name is used to
- uniquely identify a window.
-
- See the manual for detailed documentation of this interface file. }
-
- ParentPtr = ^ParentRec;
- ParentHandle = ^ParentPtr;
-
- ParentRec = RECORD
- father: ParentHandle;
- name: str255;
- wind: WindowPeek;
- rebuild: BOOLEAN; { Flag set by son to indicate that world }
- { has changed so father should rebuild list }
- END;
-
- { Standard picker record }
-
- PickPtr = ^PickRec; { Any type is OK here }
- PickHandle = ^PickPtr;
-
- ViewTypes = (viewById, viewByName, viewBySize, viewByOrder, viewBySpecial);
- PickRec = RECORD
- father: ParentHandle; { Back ptr to dad }
- fName: STR255;
- wind: WindowPtr; { Directory window }
- rebuild: BOOLEAN;
- pickID: INTEGER; { ID of this picker }
- rType: ResType; { Type for picker }
- rNum: INTEGER; { Resfile number }
- rSize: LONGINT; { Size of a null resource }
- nInsts: INTEGER; { Number of instances }
- instances: ListHandle; { List of instances }
- drawProc: Ptr; { List draw proc }
- scroll: ControlHandle; { Scroll bar }
- viewBy: ViewTypes; { Current view type }
- ldefType: ResType; { Which LDEF to use }
- theViewMenu:MenuHandle; { The picker view menu }
- showAttributes: BOOLEAN; { Show attrs in window? }
- viewMenuMask: LONGINT; { Which items are enabled? }
- cellSize: Cell; { Cell size for special view. }
- END;
-
- { These routines are used to start pickers and editors. }
-
- PROCEDURE GiveEBirth (resHandle: Handle; pick: PickHandle);
- PROCEDURE GiveSubEBirth (resHandle: Handle; pick: PickHandle);
- PROCEDURE GiveThisEBirth (resHandle: Handle; pick: PickHandle; openThisType:ResType);
-
- { These routines are used to feed events and menu calls to the appropriate picker or editor. }
- PROCEDURE CallInfoUpdate (oldID, newID: INTEGER; refcon: LONGINT; id: INTEGER );
- PROCEDURE PassMenu (menu, item: INTEGER; father: ParentHandle);
-
-
- { Window Utilities }
-
- FUNCTION AlreadyOpen (VAR windowTitle, windowName: STR255; father: ParentHandle): BOOLEAN;
- FUNCTION PickerWindSetup(color: BOOLEAN; width, height: INTEGER; VAR windowTitle: STR255;
- windowKind: INTEGER; dad: ParentHandle): WindowPtr;
- FUNCTION EditorWindSetup (dlogID: INTEGER; color: BOOLEAN; width, height: INTEGER;
- VAR windowTitle, windowName: STR255; addFrom: BOOLEAN;
- windowKind: INTEGER; father: ParentHandle): WindowPtr;
- PROCEDURE GetWindowTitle (VAR windowTitle, windowName: STR255; addFrom: BOOLEAN; father: ParentHandle);
- PROCEDURE SetETitle (h: Handle; VAR str: STR255);
- FUNCTION WindAlloc: WindowPtr;
- PROCEDURE WindReturn (w: WindowPtr);
- FUNCTION WindList (w: WindowPtr; nAcross: INTEGER; cSize: Point; drawProc:INTEGER): ListHandle;
- PROCEDURE WindOrigin (w: WindowPtr; dad: ParentHandle);
-
- { Extended Resource Manager }
-
- FUNCTION CurrentRes: INTEGER;
- FUNCTION Get1Index (t: ResType; index: INTEGER): Handle;
- FUNCTION Get1Res (t: ResType; id: INTEGER): Handle;
- FUNCTION ResEditGet1Resource (theType: ResType; ID: INTEGER; VAR wasLoaded: BOOLEAN; VAR error: INTEGER): Handle;
- FUNCTION NeedToRevert (myWindow: WindowPtr; theRes: Handle): BOOLEAN;
- PROCEDURE RemoveResource (theRes: Handle);
- FUNCTION RevertThisResource (theObj: ParentHandle; res: Handle): BOOLEAN;
- FUNCTION RestoreRemovedResources (pick: PickHandle): BOOLEAN;
- PROCEDURE ResourceIDHasChanged (theObj: ParentHandle; theType: ResType; theOldId, theNewId: INTEGER);
- FUNCTION SysResFile: INTEGER;
- FUNCTION BeautifulUnique1ID (t: ResType): INTEGER;
-
- { Miscellaneous utilities }
-
- PROCEDURE Abort;
- PROCEDURE AbleMenu(menu: INTEGER; enable: LONGINT);
- FUNCTION AddNewRes (hNew: Handle; t: ResType; idNew: INTEGER; s: str255): BOOLEAN;
- PROCEDURE BubbleUp (h: Handle);
- FUNCTION BuildType (t: ResType; l: ListHandle): INTEGER;
- FUNCTION CheckError (err, msgID: INTEGER): BOOLEAN;
- FUNCTION CloseNoSave: BOOLEAN;
- PROCEDURE ConcatStr (VAR str1: STR255; str2: STR255);
- FUNCTION DefaultListCellSize:INTEGER;
- PROCEDURE CenterDialog (theType: ResType; dialog: INTEGER);
- FUNCTION DisplaySTRAlert(which: AlertType; STRName: STR255; STRIndex: INTEGER): BOOLEAN;
- FUNCTION DisplayAlert (which: AlertType; id: INTEGER): INTEGER;
- FUNCTION DoPickBirth(color: BOOLEAN; buildList: BOOLEAN; wWidth, wHeight, columns: INTEGER;
- pickerResId: INTEGER; pick: PickHandle): BOOLEAN;
-
- { The drawProc is of the form: PROCEDURE DrawResource (lRect: Rect; theRes: Handle); }
- PROCEDURE DrawLDEF (message: INTEGER; lSelect: BOOLEAN; lRect: Rect; theRes: Handle;
- id: INTEGER; title: STR255; maxH, maxV: INTEGER;
- DrawResource: ProcPtr; lh: ListHandle);
- PROCEDURE DrawMBarLater (forceItNow: BOOLEAN);
- FUNCTION FindOwnerWindow (theRes: Handle): WindowPeek;
- PROCEDURE FixHand (s: LONGINT; h: Handle);
- PROCEDURE FlashDialogItem (dp: DialogPtr; item: integer);
- PROCEDURE FrameDialogItem (dp: DialogPtr; item: integer);
- FUNCTION GetQuickDrawVars: pQuickDrawVars;
- PROCEDURE GetStr (num, list: INTEGER; VAR str: STR255);
- PROCEDURE GetNamedStr(index: INTEGER; name: STR255; VAR str: STR255);
- PROCEDURE GrowMyWindow (minWidth, minHeight: INTEGER; windPtr: WindowPtr; lh: ListHandle);
- FUNCTION HandleCheck (h: Handle; msgID: INTEGER): BOOLEAN;
- PROCEDURE MetaKeys (VAR cmd, shift, opt: BOOLEAN);
- FUNCTION NewRes (s: LONGINT; t: ResType; l: ListHandle; VAR n: INTEGER): Handle;
- PROCEDURE PickEvent (VAR evt: EventRecord; pick: PickHandle);
- PROCEDURE PickInfoUp (oldID, newID: INTEGER; pick: PickHandle);
- PROCEDURE PickMenu (tossOnClose: BOOLEAN; menu, item: INTEGER; pick: PickHandle);
- FUNCTION PickStdHeight: INTEGER;
- FUNCTION PickStdWidth: INTEGER;
- FUNCTION PrintSetup: Handle; { Return type is actually THPrint }
- PROCEDURE PrintWindow (toPrint: PicHandle);
- FUNCTION ResEdID: INTEGER;
- PROCEDURE SendRebuildToPicker (theType: ResType; parent: ParentHandle);
- PROCEDURE SendRebuildToPickerAndFile (theType: ResType; parent: ParentHandle) ;
- PROCEDURE SetResChanged (h: Handle);
- PROCEDURE SetTheCursor (whichCursor: INTEGER);
- PROCEDURE ShowInfo (h:Handle; father: ParentHandle);
- PROCEDURE TypeToString (t: ResType; VAR s: Str255);
- PROCEDURE UseAppRes;
- FUNCTION WasAborted: BOOLEAN;
- FUNCTION WasItLoaded: BOOLEAN;
- FUNCTION ColorAvailable: BOOLEAN;
-
- { Color Palette Popup Menus }
-
- PROCEDURE InstallColorPalettePopup( whichWindow: WindowPtr; CQDishere, isActive: Boolean );
- PROCEDURE DrawColorPopup( whichWindow: WindowPtr; itemBox: Rect;
- whichColor: RGBColor; CQDishere: Boolean );
- FUNCTION ColorPalettePopupSelect( whichWindow: WindowPtr; itemBox: Rect;
- VAR whichColor: RGBColor; CQDishere: Boolean ): Boolean;
- PROCEDURE DeinstallColorPalettePopup( whichWindow: WindowPtr; CQDishere: Boolean );
-
- { Routines that are used internally withing ResEdit and may be useful in other
- circumstances. }
-
- FUNCTION MapResourceType (editor: BOOLEAN; theRes: Handle; origResType: ResType): ResType;
- PROCEDURE DoKeyScan (var evt: EventRecord; offset: integer; lh: ListHandle);
- FUNCTION DupPick (h: Handle; c: cell; pick: PickHandle): Handle;
- FUNCTION GetType (templatesOnly: BOOLEAN; VAR s: STR255): BOOLEAN;
- PROCEDURE KillCache;
- PROCEDURE MyCalcMask (srcPtr,dstPtr: Ptr; srcRow,dstRow,height,words: INTEGER);
- FUNCTION ResEditRes: INTEGER;
- Inline { move.w CurApRefNum,(sp) } $3eB8, $0900;
- PROCEDURE ScrapCopy ( VAR h: Handle );
- PROCEDURE ScrapEmpty;
- PROCEDURE ScrapPaste(pasteAll: BOOLEAN; typeToPaste: ResType; resFile: INTEGER);
- PROCEDURE WritePreferences (prefType: ResType; prefId: INTEGER; prefName: STR255; prefHandle: Handle);
- PROCEDURE GetErrorText (error: INTEGER; VAR errorText: STR255);
- FUNCTION PlaySyncSound(which: INTEGER; sndHandle: Handle): BOOLEAN;
-
- END.
-
-
-
-